/**
 * Copyright (c) 2012, Camelot and/or its affiliates. All rights reserved.
 * Camelot PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.camelot.ccr.system.dao.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.web.multipart.MultipartFile;

import com.camelot.ccr.global.dao.genericimpl.GenericHibernateDaoImpl;
import com.camelot.ccr.global.util.Pager;
import com.camelot.ccr.global.util.Utility;
import com.camelot.ccr.system.controller.DriverController;
import com.camelot.ccr.system.controller.SponsorController;
import com.camelot.ccr.system.dao.SponsorDao;
import com.camelot.ccr.system.persistence.Sponsor;

/**
 * <pre>
 * 赞助商
 * </pre>
 * @author Liu Jun
 * @version V0.1, 2014-5-20 下午10:30:05
 */
@Repository
public class SponsorDaoImpl extends GenericHibernateDaoImpl<Sponsor, String> implements SponsorDao {

	/* (non-Javadoc)
	 * @see com.camelot.ccr.system.dao.DriverDao#findPageList(int, int, com.camelot.ccr.system.persistence.Driver)
	 */
	@Override
	public Pager<Sponsor> findPageList(int curpage, int pageSize, Sponsor example) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder("from Sponsor s where 1=1  ");
		List<Object> parameList = new ArrayList<Object>();
		if(Utility.isNotNull(example.getSponsorName())){
			sb.append(" and s.sponsorName like ? ");
			parameList.add("%"+example.getSponsorName()+"%");
		}
		
		return (Pager<Sponsor>) queryListPageByHql(sb.toString(), curpage, pageSize, parameList);
	}

	@Override
	public void saveSponsor(Sponsor sponsor, MultipartFile file)
			throws IllegalStateException, IOException {
		String logoRealPathDir = sponsor.getLogoUrl();
		String photoPath = Utility.uploadFile(file, logoRealPathDir,SponsorController.headUrlPath);
		sponsor.setLogoUrl(photoPath);
		save(sponsor);
		
	}

	
}
